package org.example.query;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.example.pojo.Permission;

@Data
@NoArgsConstructor
public class PermissionQuery extends BaseQuery{
    private Long roleId;
    //这里根据一个角色的id来进行联合查询
    private String name;
    @Override
    public Wrapper getQueryWrapper() {
        MPJLambdaWrapper<Permission> wrapper=new MPJLambdaWrapper();
        wrapper.setAlias("p")
                .selectAll(Permission.class)
                .leftJoin(" role_permission rp on p.id=rp.permission_id ");
        if(roleId!=null && roleId!=0){
            wrapper.eq("role_id", roleId);
        }
        if(StringUtils.isNotEmpty(name)){
            wrapper.like("name", name);
        }
        return wrapper;
    }
}
